import { GSprite } from "../../../../com/mui/controls/GSprite";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { NoviceGiftItemRenderer } from "../novice/NoviceGiftItemRenderer";
import { ScrollPolicy } from "../../../../flashx/textLayout/container/ScrollPolicy";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { E360VipType } from "../../../../Message/Public/E360VipType";
import { Vip360GiftBagInfo } from "../../resource/info/Vip360GiftBagInfo";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GiftBagConfig } from "../../resource/GiftBagConfig";
import { Cache } from "../../cache/Cache";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { VipGetState } from "./VipGetState";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class Vip360Item
    
    export  class Vip360Item extends GSprite
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ObjCreate.createBg(0, 25, 151, 25, this, ImagesConst.Friend_over);
            this._giftBmp = ObjCreate.createBitmap(null, 0, 30, this);
            this._hadGetBmp = ObjCreate.createBitmap(null, 470, 30, this);
            this._lineBg = ObjCreate.createBitmap(null, 0, 60, this);
            this._tileList = ObjCreate.createTileList(165, 20, 430, 40, this);
            this._tileList.columnWidth = 40;
            this._tileList.rowHeight = 38;
            this._tileList.columnCount = 7;
            this._tileList.rowCount = 1;
            this._tileList.setStyle("cellRenderer", NoviceGiftItemRenderer);
            this._tileList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._tileList.verticalScrollPolicy = ScrollPolicy.OFF;
            addChild(this._tileList);
            this._getBtn = ObjCreate.createGButton("领取", 470, 30, 65, 25, this);
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Vip360GetGiftBag, this._info.vipType));
            }
            return;
        }

        /* internal  */onResLoaded(): void
        {
            if (this._info && GlobalClass.hasRes("vip360Type_" + this._info.vipType)) 
            {
                this._giftBmp.bitmapData = GlobalClass.getBitmapData("vip360Type_" + this._info.vipType);
                if (this._info.vipType == E360VipType._E360VipType6) 
                {
                    this._giftBmp.x = -73;
                }
            }
            this._hadGetBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.vip360HadGet);
            this._lineBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.vip360Line);
            return;
        }

        public setGiftInfo(arg1: Vip360GiftBagInfo): void
        {
            var loc2=null;
            this._info = arg1;
            LoaderHelp.addResCallBack(ResFileConst.Vip360, this.onResLoaded);
            if (this._info == null) 
            {
                return;
            }
            var loc1=GiftBagConfig.instance.getInfoByType(arg1.giftBagCode);
            var loc3=[];
            var loc4=0;
            var loc5=loc1;
            for(loc2 of loc5) 
            {
                if (!(loc2.type == 3 && (loc2.career == 0 || (loc2.career & Cache.instance.role.entityInfo.career) > 0))) 
                {
                    continue;
                }
                loc3.push(loc2);
            }
            this._tileList.dataProvider = new DataProvider(loc3);
            return;
        }

        public updateGetState(arg1: int): void
        {
            if (arg1 != VipGetState.vipCanGet) 
            {
                if (arg1 != VipGetState.vipCanNotGet) 
                {
                    if (arg1 == VipGetState.vipHadGet) 
                    {
                        this._hadGetBmp.visible = true;
                        this._getBtn.visible = false;
                    }
                }
                else 
                {
                    this._hadGetBmp.visible = false;
                    this._getBtn.visible = true;
                    this._getBtn.enabled = false;
                }
            }
            else 
            {
                this._hadGetBmp.visible = false;
                this._getBtn.visible = true;
                this._getBtn.enabled = true;
            }
            return;
        }

        /* internal */ /* var */_info: Vip360GiftBagInfo;

        /* internal */ /* var */_giftBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_hadGetBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tileList: GTileList;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_lineBg: Object /* flash.display.Bitmap */;
    }
